import httpUtil from "../utils/httpUtil"
import userApi from "./userApi"

const currentVerify = 710

/**
 * 审核版本控制
 */
const isVerify = (successCallBack) => {
	let params = {
		pid: 2,
		ver: currentVerify
	}
	httpUtil.post('/api/Alipayad/shenhe', params, res => {
		if (successCallBack) {
			successCallBack(res.data.is == 1)
		}
	})
}

const check = (ver, callBack) => {
	let params = {
		appid: 'wx8b15dc2c1ee47c1f',
		ver,
		type: -1,
	}
	httpUtil.post('/api/Clb/check', params, res => {
		if (callBack) {
			callBack(parseInt(res.data))
		}
	})
}

const is404 = () => {
	let params = {
		a: httpUtil.getA()
		// a: 666666,
	}
	httpUtil.postReturnSource('/api/Alipayad/status', params, res => {
		// res.code = -404
		if (res.code == -404) {
			uni.redirectTo({
				url: '/pages/404/404'
			})
		}
		// console.log('is404', res, res.code)
	})
}

/**
 * 埋点
 */
const buriedPoint = (env) => {

	let params = {
		a: httpUtil.getA(),
		openid: userApi.getUserId(),
		env,
	}
	httpUtil.postReturnSource('/api/rf/getMpUrl', params)
}

const newBuriedPoint = (proCode) => {
	let params = {
		a: httpUtil.getA(),
		proCode,
		uuid:uni.getStorageSync('uuid')
	}
	httpUtil.postReturnSource('/api/tongji/tongji0520', params)
}


export default {
	buriedPoint,
	newBuriedPoint,
	isVerify,
	is404,
	check,
}